﻿using System;
using System.Data;
using System.Linq;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void UBTAB55WB()
        {
            try
            {
                DataTable dtrSoruce = dsSource.Tables["WBBST"];
                DataTable dtVAART = dsSource.Tables["VAART"];
                DataTable dtABPOS = dsSource.Tables["ABPOS"];
                string WBBSTKNR = "",  ART = "",FARBE="", BARCODE = "",src="",SP="",VAR="",WFZZ="";
                if (dtVAART.Rows.Count > 0)
                {
                    DataRow dwVAART = dtVAART.Rows[0];
                    src = dwVAART["ARTNAME"].ToString().Trim(); 
                }
                if (dtABPOS.Rows.Count > 0)
                {
                    DataRow dwABPOS = dtABPOS.Rows[0];
                    WFZZ = dwABPOS["WFZZ"].ToString().Trim();
                    if (Helpers.Helper.Convert8859P1ToGB2312(WFZZ) == "织")
                    {
                        WFZZ = "";
                    }
                }

                int x = dsSource.Tables["WBBST"].Rows.Count;
                int i = 0;
                int rows = 7;
                foreach (DataRow dw in dtrSoruce.Rows)
                {
                    ART = dw["WBBART"].ToString().Trim();
                    //ORDERNO = dw["ORDERNO"].ToString().Trim();
                    FARBE = dw["WBBFARBE"].ToString().Trim();
                    BARCODE = "*" + dw["WBBSTKNR"].ToString().Trim() + "*";
                    WBBSTKNR = dw["WBBSTKNR"].ToString().Trim();
                    SP = dw["REMARK"].ToString().Trim();
                    VAR= dw["WBBVAR"].ToString().Trim();
                    exAgent.SetCellValue(i * rows + 1, 1, "品号/名：");
                    exAgent.SetCellValue(i * rows + 1, 4, Helpers.Helper.GetGB2312Value(ART + "  -"+FARBE+" "+src).Trim());
                    //exAgent.SetCellValue(i * rows + 1, 13, FARBE);
                    //exAgent.SetCellValue(i * rows + 2, 1, "品名："); 
                   // exAgent.SetCellValue(i * rows + 2, 4, Helpers.Helper.GetGB2312Value(src).Trim());
                    exAgent.SetCellValue(i * rows + 2, 1, "批号：");
                    exAgent.SetCellValue(i * rows + 4, 1, "边字");
                    exAgent.SetCellValue(i * rows + 4, 3, VAR);
                    exAgent.SetCellValue(i * rows + 3, 1, x+"-"+(i+1));
                    exAgent.SetCellValue(i * rows + 2, 4, Helpers.Helper.GetGB2312Value(SP).Trim());
                    exAgent.SetCellValue(i * rows + 5, 1, BARCODE);
                    exAgent.SetCellValue(i * rows + 7, 1, WBBSTKNR);
                    exAgent.SetCellValue(i * rows + 7, 12, WFZZ);
                    i = i + 1;
                    if (i < x)
                    {
                        exAgent.RangeCopy(1, 7, i * 7 + 1, i * 7 + 7);
                    }                  
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 
    }
}